package src.utils;


import src.bean.HbaseMap;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 将hbase shell 转换成已写好的方法
 */
public class HbaseShellUtils {

    /**
     * @putShell：输入put语句
     */
    public static HbaseMap put2HbaseMap(String putShell) {
        String putPattern = "^put\\s*'(.*?)'\\s*,\\s*'(.*?)'\\s*,\\s*'f1:(.*?)'\\s*,\\s*'(.*?)'$";
        Pattern p = Pattern.compile(putPattern);
        Matcher m = p.matcher(putShell);
        if (m.matches()) {
            HbaseMap hbaseMap = new HbaseMap();
            hbaseMap.setTableName(m.group(1));
            hbaseMap.setRowkey(m.group(2));
            hbaseMap.setColumnName(m.group(3));
            hbaseMap.setColumnValue(m.group(4));
            System.out.println(hbaseMap);
            return hbaseMap;
        }
        return null;
    }

    public static void main(String[] args) {
        String str = "put 'dw:t_user_register','test-ugid','f1:phone_no','15261851357'";
        put2HbaseMap(str);
    }

}
